using UnityEngine;
using System.Collections;

public class MiningJob : Job {
	
	public MiningJob(int nstartX, int nstartY, int nstartZ):base(nstartX, nstartY, nstartZ, 6){
		
	}
	
	public bool workOn(double workspeed, Robot robot){
		bool isDone = base.workOn(workspeed, robot);
		double amount = workspeed * (robot.rateOfMining);
		percentageComplete += amount;
		try {
			robot.miningTool.wearPercent += 0.001/robot.miningTool.material.strengthModifier;
			if (robot.miningTool.wearPercent > 100){
				robot.tools.Remove(robot.miningTool);
				GameObject.Destroy(robot.miningTool.item);
				robot.miningTool = null;
				robot.hasMiningTool = false;
			}
		} catch {
			
		}
		
		
		if (isDone){
			GameObject obj = (GameObject) GameObject.Instantiate(UnityEngine.Resources.Load("OrePrefab"));
			obj.transform.position = new Vector3(x, y + 3, z + 3);
			//ItemList.ores.Add(obj);
			Ore r = (Ore)obj.GetComponent("Ore");
			r.item = obj;
			int randNum = Random.Range(0, 5);
			Material mat;
			if (randNum == 0){
				mat = new Iron();
			} else if (randNum == 1){
				mat = new Tin();
			} else if (randNum == 2){
				mat = new Copper();
			} else if (randNum == 3){
				mat = new Zinc();
			} else if (randNum == 4){
				mat = new Aluminum();
			} else {
				mat = new Iron();
				Debug.Log (randNum);
			}
			r.starterate(mat);
			Debug.Log (mat.GetType().ToString());
		}
		
		return isDone;
		
	}
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
